#pragma once
#include <iostream>
using namespace std;
class Clock {
public:
	Clock(int h, int m, int s) {
		hour = (h > 23 ? 0 : h);
		minute = (m > 59 ? 0 : m);
		second = (s > 59 ? 0 : s);
	}
	virtual void run() {
		second = second + 1;
		if (second > 59)
		{
			second = 0;
			minute += 1;
		}
		if (minute > 59)
		{
			minute = 0;
			hour += 1;
		}
		if (hour > 23)
		{
			hour = 0;
		}
	}
	virtual void showTime() {
		cout << "Now:" << hour << ":" << minute << ":" << second << endl;
	}
	int getHour() { return hour; }
	int getMinute() { return minute; }
	int getSecond() { return second; }

	Clock* createClockWithDate(int h, int m, int s, int year, int month, int day);
protected:
	int hour;
	int minute;
	int second;
};



class Date {
public:
	Date(int y = 1996, int m = 1, int d = 1) {
		day = d;
		year = y;
		month = m;
		if (m > 12 || m < 1)
		{
			m = 1;
		}
		if (d > days(y, m)) {
			day = 1;
		}
	};
	int days(int year, int month);
	void NewDay();
	void display() {
		cout << year << "-" << month << "-" << day << endl;
	}
protected:
	int year;
	int month;
	int day;
};


//以下要添加，等下试试全交
int DD[13] = { -1, 31, 28 ,31, 30, 31 ,30, 31, 31 ,30 ,31, 30, 31 };
bool _Is_It_Leap_Year(int y)
{
	if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) return true;
	else return false;
}

void Date::NewDay()
{
	day += 1;
	if (_Is_It_Leap_Year(year))
	{
		DD[2] = 29;
	}
	if (day > DD[month])
	{
		month += 1;
		day = 1;
	}
	if (_Is_It_Leap_Year(year))
	{
		DD[2] = 28;
	}
	if (month > 12)
	{
		year += 1;
		month = 1;
	}
}

int Date::days(int year, int month)
{
	if (month != 2)return DD[month];
	else
	{
		if (_Is_It_Leap_Year(year))return 29;
		else return 28;
	}
}

class ClockWithDate :public Clock, public Date
{
public:
	ClockWithDate(int h, int m, int s, int year = 1996, int month = 1, int day = 1) :Clock(h, m, s), Date(year, month, day) {}
	void showTime()
	{
		Clock::showTime();
		Date::display();
	}
	void run() {
		second = second+ 1;
		if (second > 59)
		{
			second = 0;
			minute += 1;
		}
		if (minute > 59)
		{
			minute = 0;
			hour += 1;
		}
		if (hour > 23)
		{
			hour = 0;
			Date::NewDay();
		}
	}
};

Clock* Clock::createClockWithDate(int h, int m, int s, int year, int month, int day) {
	return new ClockWithDate(h, m, s, year, month, day);
}